package cn.ustb.controller;

import cn.ustb.entity.PostponeExamApply;
import cn.ustb.entity.User;
import cn.ustb.service.PostponeExamApplyService;
import cn.ustb.serviceImpl.PostponeExamServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author yuyan
 */
@WebServlet("/postponeExamApplyServlet")
public class PostponeExamApplyServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    PostponeExamApplyService postponeExamApplyService=new PostponeExamServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String yearTerm = request.getParameter("yearTerm");
        String courseName = request.getParameter("courseName");
        String applyReason = request.getParameter("applyReason");

        PostponeExamApply postponeExamApply = new PostponeExamApply(yearTerm, user.getUsername(), courseName, applyReason);
        postponeExamApplyService.insert(postponeExamApply);

        String message = "提交成功";
        session.setAttribute("message", message);
        response.sendRedirect(request.getContextPath() + "/postponeExamApply.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}